<?php
include("include/conn.php");
require('include/Smarty/libs/Smarty.class.php');
if($_GET['kaarigarMasterId'] != '')
{
	$selectKaarigar = "SELECT kaarigarmaster.kaarigarDate, kaarigardetail.particulars, kaarigardetail.crAmount, kaarigardetail.drAmount,
	                          kaarigardetail.inRojmel, kaarigar.kaarigarName , kaarigardetail.crAmount, kaarigardetail.drAmount 
	                     FROM kaarigardetail                                                                                                                                                               
	                     JOIN kaarigarmaster ON kaarigarmaster.kaarigarMasterId = kaarigardetail.kaarigarMasterId                                                                                          
	                     JOIN kaarigar ON kaarigar.kaarigarId = kaarigarmaster.kaarigarId                                                                                                                  
	                    WHERE kaarigardetail.kaarigarMasterId = ".$_GET['kaarigarMasterId']."
	                      AND inRojmel = 1";
	$selectKaarigarRes = mysql_query($selectKaarigar);
	if($row = mysql_fetch_assoc($selectKaarigarRes))
	{
		if($row['crAmount'] > 0)
		{
			$field = "Cr";
			$amount = $row['crAmount'];
		}
		else if($row['drAmount'] > 0)
		{
			$field = "Dr";
			$amount = $row['drAmount'];
		}
		  //$insertRojmel = "INSERT INTO rojmel (rojmelDate, particulars, amount, CrDr)
		    //               VALUES ('".$row['kaarigarDate']."','".$row['particulars']." (".$row['kaarigarName'].")',".$amount.",'".$field."')";
		  //$insertRojmelRes = mysql_query($insertRojmel);
	}

  //$kaarigarDetail = "DELETE FROM kaarigardetail
     //                 WHERE kaarigarMasterId =".$_GET['kaarigarMasterId'];
  //$kaarigarDetailRes = mysql_query($kaarigarDetail);
}
if(isset($_GET['rojmel']))
  header("location:rojmel.php");
else
  header("location:kaarigarDetail.php");
?>